<?php
namespace app\api\controller;
use think\Controller;
use think\Db;
class Index extends Base{
	//轮播图
	public function ads(){
        $list=Db::name('ad')->where(array('status'=>1))->order('id desc')->select();
        if($list){
            return json(['code' => 200, 'msg' => '查询成功' ,'data' =>$list]);
        }else{
            return json(['code' => 500, 'msg' => '查询失败', 'data' =>$list]);
        }
	}
    //头条速递
    public function news(){
        $list=Db::name('orders')->alias('a')->join('users b', 'a.user_id = b.id','LEFT')->field('a.money,b.phone')->order('a.id desc')->limit(5)->select();
        if($list){
            for ($i=0; $i <count($list) ; $i++) { 
                $list[$i]['phone']=substr($list[$i]['phone'],7);
            }
            return json(['code' => 200, 'msg' => '查询成功' ,'data' =>$list]);
        }else{
            return json(['code' => 500, 'msg' => '查询失败']);
        }
    }
	//产品
	public function product(){
        $list=Db::name('product')->where(array('status'=>1))->order('id desc')->select();
        if($list){
            for ($i=0; $i <count($list) ; $i++) { 
                $list[$i]['percent']=1-$list[$i]['sharemoney']/$list[$i]['totalmoney'];
                $list[$i]['percent']=round($list[$i]['percent']*100);
            }
            return json(['code' => 200, 'msg' => '查询成功' ,'data' =>$list]);
        }else{
            return json(['code' => 500, 'msg' => '查询失败', 'data' =>$list]);
        }
	}
}